const http = require("http");

/**
 * 跨域问题，不用的协议、ip、端口的下的页面发起http请求
 * 会出现跨域问题
 */
http.createServer((req,res)=>{
    if(req.url=="/"){
        var str="";
        req.on("data",(chunk)=>{
            str+=chunk;
        });
        req.on("end",()=>{
            var arr = str.split("\r\n");
            var index = arr.indexOf("")+1;
            var index2 = arr.indexOf("",index+1)+1;
            var obj = {username:arr[index],age:arr[index2]}
            console.log(obj);

            //设置允许跨域
            res.setHeader("Access-Control-Allow-Origin","*")
            res.writeHead(200,{"Content-Type":"text/plain"});
            res.end("recived");
        })
    }
}).listen(8000);
console.log("server is listening 8000")